//
//  TagCollectionItem.m
//  MacDevTest
//
//  Created by lbxia on 2022/9/3.
//  Copyright © 2022 com.lbx. All rights reserved.
//

#import "TagCollectionItem.h"

@interface TagCollectionItem ()
@property (weak) IBOutlet NSView *backview;
@property (weak) IBOutlet NSImageView *tagImageView;
@property (weak) IBOutlet NSTextField *tagTitleLabel;
@property (weak) IBOutlet NSButton *actionButton1;
@property (weak) IBOutlet NSButton *actionButton2;
@property (weak) IBOutlet NSButton *actionButton3;
@property (weak) IBOutlet NSButton *actionButton4;

@end

@implementation TagCollectionItem

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do view setup here.
    
    self.actionButton1.tag = 1;
    self.actionButton2.tag = 2;
    self.actionButton3.tag = 3;
    self.actionButton4.tag = 4;
    
    //test code
    self.tagImageView.wantsLayer = YES;
    self.tagImageView.layer.backgroundColor = NSColor.redColor.CGColor;
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    

    self.backview.wantsLayer = YES;
    
    self.backview.layer.backgroundColor = selected ? [NSColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1].CGColor : [NSColor whiteColor].CGColor;
    
    self.backview.layer.cornerRadius = 4;
    
    self.actionButton1.hidden = !selected;
    self.actionButton2.hidden = !selected;
    self.actionButton3.hidden = !selected;
    self.actionButton4.hidden = !selected;
    
}


- (IBAction)btnAction:(id)sender {
    
    NSInteger tag = ((NSButton*)sender).tag;
    
    NSLog(@"actiont tag：%ld",tag);
    
    if (_action) {
        _action(tag,_row);
    }
}

@end
